﻿using AutoMapper;
using DFGK_WMS.Context;
using DFGK_WMS.IRepository;
using DFGK_WMS.Model.DTO;
using DFGK_WMS.Model.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace DFGK_WMS.Repository
{
    public class TStationDataRepository : BaseRepository<TStationDatum>, ITStationDataRepository
    {
        public TStationDataRepository(DFGK_DB context, IMapper mapper) : base(context, mapper)
        {
        }
        /// <summary>
        /// 添加站台数据
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool AddTStationDatum(TStationDatum obj)
        {
            obj.Status = 1;
            obj.IsPickIn = false;
            obj.IsArrived = true;
            obj.IsStackFinished = true;
            obj.CreateDate = DateTime.Now;
            Context.TStationData.Add(obj);
            return Context.SaveChanges() > 0;
        }
        /// <summary>
        /// 删除站台数据
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool DelTStationDatum(int uid)
        {
            var obj = Context.TStationData.Find(uid);
            if (obj != null)
            {
                Context.TStationData.Remove(obj);
            }
            return Context.SaveChanges() > 0;
        }
        /// <summary>
        /// 修改站台数据
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public bool UpdateTStationDatum(TStationDatum obj)
        {
            var res = Context.TStationData.AsNoTracking().FirstOrDefault(s=>s.Id==obj.Id);
            if (res == null)
            {
                return false;
            }
            Context.TStationData.Update(obj);
            return Context.SaveChanges() > 0;
        }
    }
}
